Public Class frmModeratorActions
    Inherits System.Windows.Forms.Form

    Private ptrGameData As cmplib01.CampaignerGameData

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents pnlTopBorder As System.Windows.Forms.Panel
    Friend WithEvents picCampaignerIcon As System.Windows.Forms.PictureBox
    Friend WithEvents txtTitleBox As System.Windows.Forms.TextBox
    Friend WithEvents btnOK As System.Windows.Forms.Button
    Friend WithEvents lstPlayers As System.Windows.Forms.ListBox
    Friend WithEvents btnAddPlayer As System.Windows.Forms.Button
    Friend WithEvents btnRemovePlayer As System.Windows.Forms.Button
    Friend WithEvents btnEditFaction As System.Windows.Forms.Button
    Friend WithEvents lblCampaignOptions As System.Windows.Forms.Label
    Friend WithEvents chkHaltOnDetection As System.Windows.Forms.CheckBox
    Friend WithEvents chkZOC As System.Windows.Forms.CheckBox
    Friend WithEvents chkReinforcements As System.Windows.Forms.CheckBox
    Friend WithEvents chkManage As System.Windows.Forms.CheckBox
    Friend WithEvents chkOOB As System.Windows.Forms.CheckBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents lblFaction2 As System.Windows.Forms.Label
    Friend WithEvents lblFaction1 As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(frmModeratorActions))
        Me.btnRemovePlayer = New System.Windows.Forms.Button
        Me.btnAddPlayer = New System.Windows.Forms.Button
        Me.lstPlayers = New System.Windows.Forms.ListBox
        Me.pnlTopBorder = New System.Windows.Forms.Panel
        Me.picCampaignerIcon = New System.Windows.Forms.PictureBox
        Me.txtTitleBox = New System.Windows.Forms.TextBox
        Me.btnOK = New System.Windows.Forms.Button
        Me.btnEditFaction = New System.Windows.Forms.Button
        Me.chkZOC = New System.Windows.Forms.CheckBox
        Me.chkReinforcements = New System.Windows.Forms.CheckBox
        Me.chkManage = New System.Windows.Forms.CheckBox
        Me.chkOOB = New System.Windows.Forms.CheckBox
        Me.chkHaltOnDetection = New System.Windows.Forms.CheckBox
        Me.lblCampaignOptions = New System.Windows.Forms.Label
        Me.Label1 = New System.Windows.Forms.Label
        Me.lblFaction2 = New System.Windows.Forms.Label
        Me.lblFaction1 = New System.Windows.Forms.Label
        Me.Label4 = New System.Windows.Forms.Label
        Me.pnlTopBorder.SuspendLayout()
        CType(Me.picCampaignerIcon, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'btnRemovePlayer
        '
        Me.btnRemovePlayer.BackColor = System.Drawing.Color.LightSteelBlue
        Me.btnRemovePlayer.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnRemovePlayer.ForeColor = System.Drawing.Color.Black
        Me.btnRemovePlayer.Location = New System.Drawing.Point(279, 255)
        Me.btnRemovePlayer.Name = "btnRemovePlayer"
        Me.btnRemovePlayer.Size = New System.Drawing.Size(75, 24)
        Me.btnRemovePlayer.TabIndex = 2
        Me.btnRemovePlayer.Text = "Remove"
        Me.btnRemovePlayer.TextAlign = System.Drawing.ContentAlignment.TopCenter
        Me.btnRemovePlayer.UseVisualStyleBackColor = False
        '
        'btnAddPlayer
        '
        Me.btnAddPlayer.BackColor = System.Drawing.Color.LightSteelBlue
        Me.btnAddPlayer.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnAddPlayer.ForeColor = System.Drawing.Color.Black
        Me.btnAddPlayer.Location = New System.Drawing.Point(204, 255)
        Me.btnAddPlayer.Name = "btnAddPlayer"
        Me.btnAddPlayer.Size = New System.Drawing.Size(75, 24)
        Me.btnAddPlayer.TabIndex = 1
        Me.btnAddPlayer.Text = "Add"
        Me.btnAddPlayer.TextAlign = System.Drawing.ContentAlignment.TopCenter
        Me.btnAddPlayer.UseVisualStyleBackColor = False
        '
        'lstPlayers
        '
        Me.lstPlayers.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.lstPlayers.ItemHeight = 15
        Me.lstPlayers.Location = New System.Drawing.Point(189, 72)
        Me.lstPlayers.Name = "lstPlayers"
        Me.lstPlayers.Size = New System.Drawing.Size(165, 182)
        Me.lstPlayers.TabIndex = 0
        '
        'pnlTopBorder
        '
        Me.pnlTopBorder.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.pnlTopBorder.BackColor = System.Drawing.Color.SteelBlue
        Me.pnlTopBorder.Controls.Add(Me.picCampaignerIcon)
        Me.pnlTopBorder.Controls.Add(Me.txtTitleBox)
        Me.pnlTopBorder.Location = New System.Drawing.Point(0, 0)
        Me.pnlTopBorder.Name = "pnlTopBorder"
        Me.pnlTopBorder.Size = New System.Drawing.Size(358, 40)
        Me.pnlTopBorder.TabIndex = 13
        '
        'picCampaignerIcon
        '
        Me.picCampaignerIcon.Image = CType(resources.GetObject("picCampaignerIcon.Image"), System.Drawing.Image)
        Me.picCampaignerIcon.Location = New System.Drawing.Point(9, 11)
        Me.picCampaignerIcon.Name = "picCampaignerIcon"
        Me.picCampaignerIcon.Size = New System.Drawing.Size(16, 16)
        Me.picCampaignerIcon.TabIndex = 9
        Me.picCampaignerIcon.TabStop = False
        '
        'txtTitleBox
        '
        Me.txtTitleBox.BackColor = System.Drawing.Color.SteelBlue
        Me.txtTitleBox.BorderStyle = System.Windows.Forms.BorderStyle.None
        Me.txtTitleBox.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtTitleBox.ForeColor = System.Drawing.Color.WhiteSmoke
        Me.txtTitleBox.Location = New System.Drawing.Point(32, 8)
        Me.txtTitleBox.Multiline = True
        Me.txtTitleBox.Name = "txtTitleBox"
        Me.txtTitleBox.ReadOnly = True
        Me.txtTitleBox.Size = New System.Drawing.Size(312, 26)
        Me.txtTitleBox.TabIndex = 8
        Me.txtTitleBox.Text = "Campaigner [Moderator]"
        '
        'btnOK
        '
        Me.btnOK.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnOK.BackColor = System.Drawing.Color.LightSkyBlue
        Me.btnOK.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnOK.ForeColor = System.Drawing.Color.Black
        Me.btnOK.Location = New System.Drawing.Point(271, 298)
        Me.btnOK.Name = "btnOK"
        Me.btnOK.Size = New System.Drawing.Size(75, 23)
        Me.btnOK.TabIndex = 0
        Me.btnOK.Text = "Close"
        Me.btnOK.UseVisualStyleBackColor = False
        '
        'btnEditFaction
        '
        Me.btnEditFaction.BackColor = System.Drawing.Color.LightSteelBlue
        Me.btnEditFaction.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnEditFaction.ForeColor = System.Drawing.Color.Black
        Me.btnEditFaction.Location = New System.Drawing.Point(102, 110)
        Me.btnEditFaction.Name = "btnEditFaction"
        Me.btnEditFaction.Size = New System.Drawing.Size(75, 23)
        Me.btnEditFaction.TabIndex = 1
        Me.btnEditFaction.Text = "Edit"
        Me.btnEditFaction.UseVisualStyleBackColor = False
        '
        'chkZOC
        '
        Me.chkZOC.BackColor = System.Drawing.Color.Gainsboro
        Me.chkZOC.ForeColor = System.Drawing.Color.Black
        Me.chkZOC.Location = New System.Drawing.Point(11, 236)
        Me.chkZOC.Name = "chkZOC"
        Me.chkZOC.Size = New System.Drawing.Size(164, 19)
        Me.chkZOC.TabIndex = 3
        Me.chkZOC.Text = "Use Zones of Control"
        Me.chkZOC.UseVisualStyleBackColor = False
        '
        'chkReinforcements
        '
        Me.chkReinforcements.BackColor = System.Drawing.Color.Gainsboro
        Me.chkReinforcements.ForeColor = System.Drawing.Color.Black
        Me.chkReinforcements.Location = New System.Drawing.Point(11, 212)
        Me.chkReinforcements.Name = "chkReinforcements"
        Me.chkReinforcements.Size = New System.Drawing.Size(164, 19)
        Me.chkReinforcements.TabIndex = 2
        Me.chkReinforcements.Text = "Allow reinforcements"
        Me.chkReinforcements.UseVisualStyleBackColor = False
        '
        'chkManage
        '
        Me.chkManage.BackColor = System.Drawing.Color.Gainsboro
        Me.chkManage.ForeColor = System.Drawing.Color.Black
        Me.chkManage.Location = New System.Drawing.Point(11, 189)
        Me.chkManage.Name = "chkManage"
        Me.chkManage.Size = New System.Drawing.Size(164, 19)
        Me.chkManage.TabIndex = 1
        Me.chkManage.Text = "Players manage chits"
        Me.chkManage.UseVisualStyleBackColor = False
        '
        'chkOOB
        '
        Me.chkOOB.BackColor = System.Drawing.Color.Gainsboro
        Me.chkOOB.ForeColor = System.Drawing.Color.Black
        Me.chkOOB.Location = New System.Drawing.Point(11, 166)
        Me.chkOOB.Name = "chkOOB"
        Me.chkOOB.Size = New System.Drawing.Size(164, 19)
        Me.chkOOB.TabIndex = 0
        Me.chkOOB.Text = "Allow only order of battle"
        Me.chkOOB.UseVisualStyleBackColor = False
        '
        'chkHaltOnDetection
        '
        Me.chkHaltOnDetection.BackColor = System.Drawing.Color.Gainsboro
        Me.chkHaltOnDetection.ForeColor = System.Drawing.Color.Black
        Me.chkHaltOnDetection.Location = New System.Drawing.Point(11, 259)
        Me.chkHaltOnDetection.Name = "chkHaltOnDetection"
        Me.chkHaltOnDetection.Size = New System.Drawing.Size(164, 19)
        Me.chkHaltOnDetection.TabIndex = 4
        Me.chkHaltOnDetection.Text = "Halt on Detection"
        Me.chkHaltOnDetection.UseVisualStyleBackColor = False
        '
        'lblCampaignOptions
        '
        Me.lblCampaignOptions.BackColor = System.Drawing.Color.SteelBlue
        Me.lblCampaignOptions.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.lblCampaignOptions.Location = New System.Drawing.Point(6, 140)
        Me.lblCampaignOptions.Name = "lblCampaignOptions"
        Me.lblCampaignOptions.Size = New System.Drawing.Size(170, 24)
        Me.lblCampaignOptions.TabIndex = 19
        Me.lblCampaignOptions.Text = "Campaign Options"
        Me.lblCampaignOptions.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'Label1
        '
        Me.Label1.BackColor = System.Drawing.Color.SteelBlue
        Me.Label1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.Label1.Location = New System.Drawing.Point(7, 48)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(170, 24)
        Me.Label1.TabIndex = 20
        Me.Label1.Text = "Factions"
        Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'lblFaction2
        '
        Me.lblFaction2.BackColor = System.Drawing.Color.Gainsboro
        Me.lblFaction2.Location = New System.Drawing.Point(11, 92)
        Me.lblFaction2.Name = "lblFaction2"
        Me.lblFaction2.Size = New System.Drawing.Size(165, 17)
        Me.lblFaction2.TabIndex = 21
        Me.lblFaction2.Text = "Faction 2"
        Me.lblFaction2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'lblFaction1
        '
        Me.lblFaction1.BackColor = System.Drawing.Color.Gainsboro
        Me.lblFaction1.Location = New System.Drawing.Point(11, 73)
        Me.lblFaction1.Name = "lblFaction1"
        Me.lblFaction1.Size = New System.Drawing.Size(165, 17)
        Me.lblFaction1.TabIndex = 22
        Me.lblFaction1.Text = "Faction 1"
        Me.lblFaction1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'Label4
        '
        Me.Label4.BackColor = System.Drawing.Color.SteelBlue
        Me.Label4.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.Label4.Location = New System.Drawing.Point(184, 48)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(170, 24)
        Me.Label4.TabIndex = 19
        Me.Label4.Text = "Players"
        Me.Label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'frmModeratorActions
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.BackColor = System.Drawing.Color.Black
        Me.ClientSize = New System.Drawing.Size(358, 333)
        Me.Controls.Add(Me.chkZOC)
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.chkReinforcements)
        Me.Controls.Add(Me.lstPlayers)
        Me.Controls.Add(Me.chkManage)
        Me.Controls.Add(Me.lblFaction1)
        Me.Controls.Add(Me.chkOOB)
        Me.Controls.Add(Me.chkHaltOnDetection)
        Me.Controls.Add(Me.btnRemovePlayer)
        Me.Controls.Add(Me.btnAddPlayer)
        Me.Controls.Add(Me.lblCampaignOptions)
        Me.Controls.Add(Me.lblFaction2)
        Me.Controls.Add(Me.btnEditFaction)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.btnOK)
        Me.Controls.Add(Me.pnlTopBorder)
        Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow
        Me.Name = "frmModeratorActions"
        Me.ShowInTaskbar = False
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.pnlTopBorder.ResumeLayout(False)
        Me.pnlTopBorder.PerformLayout()
        CType(Me.picCampaignerIcon, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region

    Public Sub New(ByRef gameData As cmplib01.CampaignerGameData)

        Me.New()

        Dim obj As Object = gameData.SystemValue("datamap")
        Dim datamap() As Byte

        If TypeOf obj Is String Then
            gameData.SetUpDataMapping()
            datamap = gameData.SystemValue("datamap")
        Else
            datamap = obj
        End If

        If datamap(221) = 0 Then
            '// not a demo
        Else
            '// in demo games these values are SET
            With Me
                .chkHaltOnDetection.Enabled = False
                .chkManage.Enabled = False
                .chkOOB.Enabled = False
                .chkReinforcements.Enabled = False
                .chkZOC.Enabled = False
            End With
        End If

        ptrGameData = gameData
        ListPlayers()
        ListFactions()
        ListOptions()

    End Sub

    Private Sub ListOptions()
        Try

            With Me
                .chkHaltOnDetection.Checked = ptrGameData.haltOnNewDetection
                .chkManage.Checked = ptrGameData.AllowPlayerManageChits
                .chkOOB.Checked = ptrGameData.ForceOOB
                .chkReinforcements.Checked = ptrGameData.AllowReinforcements
                .chkZOC.Checked = ptrGameData.UsesZOC
            End With

        Catch ex As Exception
            HandleException("frmModeratorActions.ListOptions", ex)
        End Try
    End Sub

    Private Sub ListPlayers()
        Dim play As cmplib01.Player
        Dim key As String

        lstPlayers.Items.Clear()

        For Each key In ptrGameData.Players.Keys
            play = ptrGameData.Players.Item(key)
            lstPlayers.Items.Add(play)
        Next
    End Sub

    Private Sub ListFactions()
        ' populate faction one and two data
        Dim key As String
        Dim fac As cmplib01.Faction

        Dim i As Integer


        For Each key In ptrGameData.Faction_g.HT.Keys
            fac = ptrGameData.Faction_g.Item(key)
            If i = 0 Then
                lblFaction1.Text = fac.FactionName
                i += 1
            Else
                lblFaction2.Text = fac.FactionName
            End If
        Next
    End Sub

    Private Sub btnAddPlayer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddPlayer.Click
        Dim newPlayer As New cmplib01.Player()
        newPlayer.PlayerName = "New Player"

        Dim frmNewPlayer As New frmAddPlayer(newPlayer, ptrGameData.Faction_g)
        frmNewPlayer.ShowDialog()

        If Not frmNewPlayer.ActionCancelled Then
            Try
                ptrGameData.Players.Add(newPlayer.PlayerName, newPlayer)
                ptrGameData.LogEvents.Add(New cmplib01.CampaignerLogEvent("New player added: " & newPlayer.PlayerName, "Moderator", ptrGameData.ElapsedTime.ToString, "<none>", cmplib01.EventAuthorityLevel.PublicEvent))
                ListPlayers()
            Catch ex As Exception
                MessageBox.Show("A player with that name already exists. Please choose a different name.", "Invalid Player", MessageBoxButtons.OK)
            End Try
        End If

    End Sub

    Private Sub btnRemovePlayer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemovePlayer.Click
        RemoveSelectedPlayer()
    End Sub

    Private Sub RemoveSelectedPlayer()
        If lstPlayers.SelectedItem Is Nothing Then
            MessageBox.Show("You must select a player to remove first.", "Select Player", MessageBoxButtons.OK)
            Exit Sub
        End If

        Dim play As cmplib01.Player
        play = lstPlayers.SelectedItem

        If play.PlayerName = "<Moderator>" Then
            MessageBox.Show("The Moderator cannot be deleted.", "Invalid Action", MessageBoxButtons.OK)
            Exit Sub
        End If

        If MessageBox.Show("Are you sure you wish to delete this player and all of units belonging to this player?", "Delete Player", MessageBoxButtons.YesNo) = DialogResult.Yes Then
            ptrGameData.Players.Remove(play.PlayerName)
            'TASK: Delete a players units and stuff, and other logical stuff. Also, moderator actions will include reassigning
            ' player units. The point value for depleted units will go into the factions pool.
        End If

        ListPlayers()

    End Sub

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

        With Me
            ptrGameData.haltOnNewDetection = .chkHaltOnDetection.Checked
            ptrGameData.AllowPlayerManageChits = .chkManage.Checked
            ptrGameData.ForceOOB = .chkOOB.Checked
            ptrGameData.AllowReinforcements = .chkReinforcements.Checked
            ptrGameData.UsesZOC = .chkZOC.Checked
        End With

        Me.Hide()
    End Sub

    Private Sub btnEditFaction_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEditFaction.Click
        Dim frmEditFac As New frmEditFactions(ptrGameData.Faction_g)
        frmEditFac.ShowDialog()

    End Sub
End Class
